$(function() {

    var x_formForm = "#prices_form";
    var x_formSelect = "#prices_form select";
    var x_formHotelID = "#prices_form #hotel_id";
    var x_formTrigger = "#prices_form #nr_adults";
    var x_formMask = ".calculation";
    var resultsHTML = {
        'nr_adults': '#nr_adults',
        'nr_childrens': '#nr_childrens',
        'nr_teenagers': '#nr_teenagers',
        'nr_babies': '#nr_babies',
        'check_in': '#check_in',
        'check_out': '#check_out',
        'service_persons': '.service_persons',
        'service_periods': '.service_periods',
        'service_total': '.service_total',
        'tax_city': '.tax_city',
        'tax_insurance': '.tax_insurance',
        'tax_eco': '.tax_eco',
        'total': '.total span',
        'too_many': '.too_many'
    }

    var myCalculation = new API.x_calculation.CalculationManager(x_formForm, x_formSelect, x_formHotelID, x_formTrigger, x_formMask, resultsHTML, API.Data.lang);

    myCalculation.Initialize();

    var myItems = d;
    var isPreview = preview;  // is dates submit or not

    var myCalendar = new API.x_calendar.CalendarManager(myItems, API.Data.lang, isPreview, x_formTrigger);

    myCalendar.Initialize();

    $("#book_now_input_default").live('click', function() {     // glavno input dugme na strani detalji unutar forme

        if (myCalculation.Data.available === false) {
            alert(myCalculation.Data.message);
            return false;
        }

    });

    $("#book_now_input").live('click', function() {     //pomocno dugme van forme

        if (myCalculation.Data.available === false) {

            $.scrollTo('#scrool_to_price', 500);
            $("#tabs").tabs("option", "active", 1);
        } else {
            $('#prices_form').submit();
        }

        return false;
    });

    $("#show_on_map").live('click', function() {     //pomocno dugme van forme

        $.scrollTo('#scrool_to_price', 500);
        $("#do_google_map").trigger('click');

        return false;
    });

    $(".view_all_reviews").live('click', function() {     //pomocno dugme van forme

        $.scrollTo('#scrool_to_price', 500);
        $("#view_reviews").trigger('click');

        return false;
    });

});